import {defHttp} from '/@/utils/http/axios';
import {
  StaffInfo,
  PersonalLeaderParam,
} from "./model/staffModel";
import {BasicPageSearchParams, CheckExistParams} from "/@/api/model/baseModel";

enum Api {
  list = '/org/staff/list',
  view = '/org/staff/view/',
  add = '/org/staff/add',
  del = '/org/staff/del/',
  update = '/org/staff/update',
  getAll = '/org/staff/getAll/',


  Delete = '/org/staff/delete',
  SetLeaderCode = '/org/staff/setLeaderCode',
  CheckEntityExist = '/org/staff/checkEntityExist',
  DeletePersonalRole = '/org/staffRole/deletePersonalRole',
}

//列表
export const list = (params?: any) => {
  const query = params && { pageNum: params.pageNum, pageSize: params.pageSize };
  let entity = params || {};
  if (entity) {
    delete entity['pageNum'];
    delete entity['pageSize'];
  }
  const queryParam = { query, entity } as BasicPageSearchParams<any>;
  return defHttp.post<any>({ url: Api.list, params: queryParam });
};

export const view = (id?: number) => {
  return defHttp.get<any>({ url: Api.view + id });
};

export const add = (params?: StaffInfo) =>
  defHttp.post<StaffInfo>({url: Api.add, params});

export const update = (params?: StaffInfo) =>
  defHttp.post<StaffInfo>({url: Api.update, params});

export const del = (id?: number) =>
  defHttp.post<any>({ url: Api.del + id });


export const deleteByIds = (params?: Array<string>) =>
  defHttp.post({url: Api.Delete, params});


export const setLeaderCode = (params: PersonalLeaderParam) =>
  defHttp.post({url: Api.SetLeaderCode + `/${params.leaderCode}/${params.id}`});

export const checkEntityExist = (params?: CheckExistParams) =>
  defHttp.post<boolean>({ url: Api.CheckEntityExist, params });
